﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HU8.Web.FileExplorer.FileExplorer.Config;
using System.Xml;
using HU8.Helpers.Files;
using System.Web.UI;
using System.Configuration;

namespace XMK.Tadong.Web.Language
{
          
    public class FileExplorerConfig
    {
        private XmlDocument xml;
        private string configPath;
        private string basePath;
        private Dictionary<string, string> languages;
        private LanguageDictionary lang;
        private string subPath = "";
        HttpContext Context = null;
        string sub_path = "";
        public FileExplorerConfig(HttpServerUtility server, HttpContext context)
        {
            Context = context;

            configPath = server.MapPath(ConfigurationManager.AppSettings.Get("LanguagePath") + "/Language/config.xml");
            basePath = server.MapPath("~/");
            xml = new XmlDocument();
            xml.Load(configPath);
            //现有的语言列表
            languages = new Dictionary<string, string>();
            foreach (XmlNode n in xml.SelectNodes("//Languages/add"))
            {
                string key = n.Attributes["key"].Value.Trim(); ;
                string value = n.Attributes["value"].Value.Trim(); ;
                languages.Add(key, value);
            }
            //Load Language
            lang = new LanguageDictionary(Language, server);
              /// <summary>
       
        }
        /// 软件语言
        /// </summary>
        public string Language
        {
            get
            {
                return getSingleNodeAttribute("//FileExplorer", "lang");
            }
            set
            {
                setSingleNodeAttribute("//FileExplorer", "lang", value);
            }
        }
        private string getSingleNodeAttribute(string xpath, string attrName)
        {
            XmlNode node = xml.SelectSingleNode(xpath);
            if (node != null)
            {
                return node.Attributes[attrName].Value;
            }
            else
            {
                return "";
            }
        }

        private void setSingleNodeAttribute(string xpath, string attrName, string value)
        {
            XmlNode node = xml.SelectSingleNode(xpath);
            if (node != null)
            {
                node.Attributes[attrName].Value = value;
            }
        }
    }
}